<?php

/**
 * This is the model class for table "materiel".
 *
 * The followings are the available columns in table 'materiel':
 * @property integer $ID_MATERIEL
 * @property integer $ID_TYPE_MATERIEL
 * @property string $NOM_MATERIEL
 * @property string $REFERENCE_MATERIEL
 * @property string $DESCRIPTION_MATERIEL
 * @property string $CONSTRUCTEUR_MATERIEL
 *
 * The followings are the available model relations:
 * @property Poste[] $postes
 * @property TypeMateriel $iDTYPEMATERIEL
 */
class Materiel extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Materiel the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'materiel';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('ID_TYPE_MATERIEL, NOM_MATERIEL, REFERENCE_MATERIEL, CONSTRUCTEUR_MATERIEL', 'required'),
			array('ID_TYPE_MATERIEL', 'numerical', 'integerOnly'=>true),
			array('NOM_MATERIEL, REFERENCE_MATERIEL, CONSTRUCTEUR_MATERIEL', 'length', 'max'=>20),
			array('DESCRIPTION_MATERIEL', 'length', 'max'=>200),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('ID_MATERIEL, ID_TYPE_MATERIEL, NOM_MATERIEL, REFERENCE_MATERIEL, DESCRIPTION_MATERIEL, CONSTRUCTEUR_MATERIEL', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'postes' => array(self::MANY_MANY, 'Poste', 'configuration_materielle(ID_MATERIEL, ID_POSTE)'),
			'iDTYPEMATERIEL' => array(self::BELONGS_TO, 'TypeMateriel', 'ID_TYPE_MATERIEL'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'ID_MATERIEL' => 'Id Materiel',
			'ID_TYPE_MATERIEL' => 'Id Type Materiel',
			'NOM_MATERIEL' => 'Nom Materiel',
			'REFERENCE_MATERIEL' => 'Reference Materiel',
			'DESCRIPTION_MATERIEL' => 'Description Materiel',
			'CONSTRUCTEUR_MATERIEL' => 'Constructeur Materiel',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('ID_MATERIEL',$this->ID_MATERIEL);
		$criteria->compare('ID_TYPE_MATERIEL',$this->ID_TYPE_MATERIEL);
		$criteria->compare('NOM_MATERIEL',$this->NOM_MATERIEL,true);
		$criteria->compare('REFERENCE_MATERIEL',$this->REFERENCE_MATERIEL,true);
		$criteria->compare('DESCRIPTION_MATERIEL',$this->DESCRIPTION_MATERIEL,true);
		$criteria->compare('CONSTRUCTEUR_MATERIEL',$this->CONSTRUCTEUR_MATERIEL,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}